limsProductMain.mainChoosePage = {

    getGridParam: function () {
        var _this = this, columns = limsProductMain.getProductSubChooseColumns(), requestData = this.param;
        requestData.status_EQ = '1';
        return {
            type: 'grid',
            id: 'product-main-choose-list-grid',
            url: limsProductMain.baseUrl + '/queries/choosable',
            page: true,
            requestData: requestData,
            filterOpen: true,
            readonly: true,
            columns: columns,
            radio: true,
            onLoadSuccess: function (data) {
                if (!Gikam.isEmpty(data)) {
                    this.activeRowByIndex(0);
                } else {
                    Gikam.getComp('product-method-list-grid').cleanData()
                }
            },
            // 选中行
            onRowActive: function (index, row) {
                _this.loadProductMethodList(row.id);
            },
            activateFirstRow: true,
            activeOnCheck: true
        }
    },

    //加载方法
    loadProductMethodList: function (id) {
        var _this = this;
        if (id) {
            var methodUrl = limsProductMain.productPurposeUrl + '/queries';
            Gikam.getAsyncComp('product-method-list-grid').done(function (methodGrid) {
                methodGrid.setOptions({
                    url: methodUrl,
                    requestData: {
                        productMainId_EQ: id
                    }
                });
                methodGrid.refresh();
            });
        }
    },

    //方法
    getProductMethodGridParam: function () {
        var _this = this;
        return {
            type: 'grid',
            id: 'product-method-list-grid',
            checkOnActive: true,
            columns: _this.getProductPurposeListColumns(),
            service: 'limsProductMainPuposeServiceImpl',
            toolbar: [],
            activateFirstRow: true,
            activeOnCheck: true,
            radio: true,
        }
    },

    getBtnToolbarParam: function () {
        var _this = this;
        return {
            type: 'btnToolbar',
            items: [{
                type: 'btnGroup',
                items: [{
                    type: 'button',
                    text: 'GIKAM.BUTTON.CONFIRM',
                    icon: 'select',
                    onClick: function () {
                        var productRow = Gikam.getComp('product-main-choose-list-grid').getActivedRow()
                        var methodRow = Gikam.getComp('product-method-list-grid').getActivedRow()
                        Gikam.getLastModal().close({
                            productRow: productRow,
                            methodRow: methodRow
                        });
                    }
                }, {
                    type: 'button',
                    text: 'GIKAM.BUTTON.CANCEL',
                    icon: 'cancel',
                    onClick: function () {
                        Gikam.getLastModal().close();
                    }
                }]
            }]
        }
    },

    getProductPurposeListColumns: function () {
        return [{
            radio: true
        }, {
            index: true
        }, {
            field: 'purposeCode',
            width: 140,
            title: 'T_LIMS_PURPOSE.PURPOSECODE'
        }, {
            field: 'purposeName',
            title: 'T_LIMS_PURPOSE.PURPOSENAME',
            width: 220,
        }, {
            field: 'purposeType',
            title: 'T_LIMS_PURPOSE.PURPOSETYPE',
            type: 'select',
            category: 'sys',
            param: {
                codeCategoryId: 'purposetype'
            },
        },];
    },

    create: function () {
        var _this = this;
        Gikam.create('layout', {
            renderTo: Gikam.getLastModal().window.$dom,
            north: {
                items: [this.getBtnToolbarParam(), this.getGridParam()],
                height: '50%'
            },
            center: {
                items: [this.getProductMethodGridParam()]
            }
        });
    },

    init: function (param) {
        this.param = param;
        this.create();
    }
};
